const express = require("express");
const consola = require("consola");
var routes = require("./routes/index");

var log4js = require("./plugins/log4j");
var bodyParser = require("body-parser");
const app = express();
log4js.configure();
app.use(log4js.useLog());
app.use(bodyParser.json()); //body-parser 解析json格式数据
routes(app);
app.use(express.static('static'));
var config = require("./config/index");
let port = config.server.port || 300 ;
let host = config.server.host || "0.0.0.0";
async function start() {
  var server = require("http").createServer(app);
  // 开起socket
  var io = require("socket.io").listen(server);
  require("./plugins/socket").init(io);
  server.listen(port, host, function () {
    var host = server.address().address;
    var port = server.address().port;
    console.log("应用实例，访问地址为 http://%s:%s", host, port);
  });
  // consola.ready({
  //   message: `Server listening on http://${host}:${port}`,
  //   badge: true
  // })
}
start();
